home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir42 / gnudbm14.zip / UNIX / DBMSEQ.C < prev    next >
C/C++ Source or Header  |  1990-08-14  |  3KB  |  83 lines

  1. /* dbmseq.c - Visit all elements in the database.  This is the NDBM
  2.    interface. */
  3.  
  4. /*  This file is part of GDBM, the GNU data base manager, by Philip A. Nelson.
  5.     Copyright (C) 1990  Free Software Foundation, Inc.
  6.  
  7.     GDBM is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 1, or (at your option)
  10.     any later version.
  11.  
  12.     GDBM is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with GDBM; see the file COPYING.  If not, write to
  19.     the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.     You may contact the author by:
  22.        e-mail:  phil@wwu.edu
  23.       us-mail:  Philip A. Nelson
  24.                 Computer Science Department
  25.                 Western Washington University
  26.                 Bellingham, WA 98226
  27.         phone:  (206) 676-3035
  28.        
  29. *************************************************************************/
  30.  
  31.  
  32. #include <stdio.h>
  33. #include <sys/types.h>
  34. #include <sys/file.h>
  35. #include <sys/stat.h>
  36. #include "gdbmdefs.h"
  37. #include "extern.h"
  38.  
  39.  
  40. /* NDBM Start the visit of all keys in the database.  This produces
  41.    something in hash order, not in any sorted order.  DBF is the dbm file
  42.    information pointer. */
  43.  
  44. datum
  45. dbm_firstkey (dbf)
  46.      gdbm_file_info *dbf;
  47. {
  48.   datum ret_val;
  49.  
  50.   /* Free previous dynamic memory, do actual call, and save pointer to new
  51.      memory. */
  52.   ret_val = gdbm_firstkey (dbf);
  53.   if (_gdbm_memory.dptr != NULL) free (_gdbm_memory.dptr);
  54.   _gdbm_memory = ret_val;
  55.  
  56.   /* Return the new value. */
  57.   return ret_val;
  58. }
  59.  
  60.  
  61. /* NDBM Continue visiting all keys.  The next key in the sequence is returned.
  62.    DBF is the file information pointer. */
  63.  
  64. datum
  65. dbm_nextkey (dbf)
  66.      gdbm_file_info *dbf;
  67. {
  68.   datum ret_val;
  69.  
  70.   /* Make sure we have a valid key. */
  71.   if (_gdbm_memory.dptr == NULL)
  72.     return _gdbm_memory;
  73.  
  74.   /* Call gdbm nextkey with the old value. After that, free the old value. */
  75.   ret_val = gdbm_nextkey (dbf,_gdbm_memory);
  76.   if (_gdbm_memory.dptr != NULL) free (_gdbm_memory.dptr);
  77.   _gdbm_memory = ret_val;
  78.  
  79.   /* Return the new value. */
  80.   return ret_val;
  81. }
  82.  
  83.